/*
 *  InitParam.cpp
 *  Milovo03epsilon03
 *
 *  Created by luca on 04/08/06.
 *  Copyright 2006 __MyCompanyName__. All rights reserved.
 *
 */

#include "InitParam.h"

MilinitParams::MilinitParams()
{
	NumAgents = 10;
	NumMinRecipesPerAgent = 2;
	NumMaxRecipesPerAgent = 3;
	NumMinArtifactsPerRecipe = 2;
	NumMaxArtifactsPerRecipe = 3;
	ValidateRecipeOutputInitNet = 2;
	UseTypeNetwork = 0;
	SeedRandomValue = 12345; 
	StartActivityAgents = 10.0;
}

MilinitParams::MilinitParams(Mil_Int tmpNumAgents, Mil_Int tmpNumMinRecipesPerAgent, Mil_Int tmpNumMaxRecipesPerAgent, Mil_Int tmpNumMinArtifactsPerRecipe,
									  Mil_Int tmpNumMaxArtifactsPerRecipe, Mil_Int tmpUseTypeNetwork, Mil_Int tmpSeedRandomValue, Mil_Double tmpStartActivityAgents, 
									  Mil_Int tmpValidateRecipeOutputInitNet)
{
	NumAgents = tmpNumAgents;
	NumMinRecipesPerAgent = tmpNumMinRecipesPerAgent;
	NumMaxRecipesPerAgent = tmpNumMaxRecipesPerAgent;
	NumMinArtifactsPerRecipe = tmpNumMinArtifactsPerRecipe;
	NumMaxArtifactsPerRecipe = tmpNumMaxArtifactsPerRecipe;
	ValidateRecipeOutputInitNet = tmpValidateRecipeOutputInitNet;
	UseTypeNetwork = tmpUseTypeNetwork;
	SeedRandomValue = tmpSeedRandomValue; 
	StartActivityAgents = tmpStartActivityAgents;
}

MilinitParams::~MilinitParams()
{
}

void MilinitParams::LoadInitNetParam(string srtPath)
{
	string tmpFileInitnetParam(srtPath);
	ifstream in(tmpFileInitnetParam.c_str());
	
	string tmpSingleParam;
	while(getline(in, tmpSingleParam))
	{
		Mil_Int tmpEqualPos;
		if(tmpSingleParam.find("#"))
		{
			tmpEqualPos = tmpSingleParam.find("=");
			string tmpNameSingleParam(tmpSingleParam, 0, tmpEqualPos);
			string tmpValueSingleParam(tmpSingleParam, tmpEqualPos + 1, tmpSingleParam.size());
			if(tmpNameSingleParam == "NumAgents") NumAgents = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "NumMinRecipesPerAgent") NumMinRecipesPerAgent = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "NumMaxRecipesPerAgent") NumMaxRecipesPerAgent = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "NumMinArtifactsPerRecipe") NumMinArtifactsPerRecipe = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "NumMaxArtifactsPerRecipe") NumMaxArtifactsPerRecipe = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "ValidateRecipeOutputInitNet") ValidateRecipeOutputInitNet = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "StartActivityAgents") StartActivityAgents = atof(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "UseTypeNetwork") UseTypeNetwork = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "SeedRandomValue") SeedRandomValue = atol(tmpValueSingleParam.c_str());
		}
	}
}

void MilinitParams::LoadRawMaterials(string strPath)
{
	string StrFileLoadRawMaterial = strPath + "MilovoRawMaterial.conf";
	
	ifstream fid_LoadRawMaterial;
	fid_LoadRawMaterial.open(StrFileLoadRawMaterial.c_str(),ios::in);
	string tmpSingleLine;
	while(getline(fid_LoadRawMaterial, tmpSingleLine))
	{
		Mil_Int tmpNameThisRawMaterial = atol(tmpSingleLine.c_str());
		VectRawMaterials.push_back(tmpNameThisRawMaterial);
	}	
	fid_LoadRawMaterial.close();
}

void MilinitParams::LoadOperators(string strPath)
{
	string StrFileLoadOperators = strPath + "MilovoOperators.conf";
	
	ifstream fid_LoadOperators;
	fid_LoadOperators.open(StrFileLoadOperators.c_str(),ios::in);
	string tmpSingleLine;
	while(getline(fid_LoadOperators, tmpSingleLine))
	{
		Mil_Int tmpOperatorType = atol(tmpSingleLine.c_str());
		VectOperators.push_back(tmpOperatorType);
	}
	fid_LoadOperators.close();
	
	for(Mil_Int i = 0; i < VectOperators.size(); i++)
		cout << "Operator: " << VectOperators[i] << endl;
}

void MilinitParams::PrintInitNetParam()
{
	cout << " -- BEGIN PRINT INITNET PARAMETER" << endl;
	cout << "NumAgents: " << NumAgents << endl;
	cout << "NumMinRecipesPerAgent: " << NumMinRecipesPerAgent << endl;
	cout << "NumMaxRecipesPerAgent: " << NumMaxRecipesPerAgent << endl;
	cout << "NumMinArtifactsPerRecipe: " << NumMinArtifactsPerRecipe << endl;
	cout << "NumMaxArtifactsPerRecipe: " << NumMaxArtifactsPerRecipe << endl;
	cout << "UseTypeNetwork: " << UseTypeNetwork << endl;
	cout << "SeedRandomValue: " << SeedRandomValue << endl; 
	cout << "StartActivityAgents: " << StartActivityAgents << endl;
	cout << " -- END PRINT INITNET PARAMETER" << endl;
}

